import { IsString, IsNumber, IsBoolean, IsDate, IsOptional, IsEnum, IsArray } from 'class-validator';
import { ApiProperty, OmitType, IntersectionType } from '@nestjs/swagger';
import { PagingDto } from 'src/common/dto/index';
import { CharEnum } from 'src/common/enum/index';
import { Type } from 'class-transformer';

export class BaseOrderDto {
  @ApiProperty({ required: false, description: '订单ID' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  id?: number;

  @ApiProperty({ required: false, description: '订单编号' })
  @IsOptional()
  @IsString()
  orderNo?: string;

  @ApiProperty({ required: false, description: '用户ID' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  userId?: number;

  @ApiProperty({ required: false, description: '订单总金额(分)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  totalAmount?: number;

  @ApiProperty({ required: false, description: '实付金额(分)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  payAmount?: number;

  @ApiProperty({ required: false, description: '折扣金额(分)' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  discountAmount?: number;

  @ApiProperty({ required: false, description: '订单状态：0-待支付，1-已支付，2-已取消，3-已关闭，4-已退款' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  orderStatus?: number;

  @ApiProperty({ required: false, description: '支付方式：1-微信支付' })
  @IsOptional()
  @IsNumber()
  @Type(() => Number)
  payType?: number;

  @ApiProperty({ required: false, description: '商品名称' })
  @IsOptional()
  @IsString()
  productName?: string;

  @ApiProperty({ required: false, description: '商品描述' })
  @IsOptional()
  @IsString()
  productDesc?: string;

  @ApiProperty({ required: false, description: '支付时间' })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  payTime?: Date;

  @ApiProperty({ required: false, description: '取消时间' })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  cancelTime?: Date;

  @ApiProperty({ required: false, description: '关闭时间' })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  closeTime?: Date;

  @ApiProperty({ required: false, description: '备注' })
  @IsOptional()
  @IsString()
  remark?: string;

  @ApiProperty({ required: false, description: '创建时间' })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  createTime?: Array<string>;

  @ApiProperty({ required: false, description: '更新时间' })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  updateTime?: Array<string>;
}

export class CreateOrderDto extends OmitType(BaseOrderDto, ['id', 'createTime']) {}

export class UpdateOrderDto extends OmitType(BaseOrderDto, ['createTime']) {}

export class QueryOrderDto extends IntersectionType(BaseOrderDto, PagingDto) {}

export class ListOrderDto extends OmitType(BaseOrderDto, ['createTime', 'updateTime']) {}
